package com.zhouyibike.uu.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.entity.Cityinfo;
import com.zhouyibike.uu.entity.Mycity2;
import com.zhouyibike.uu.entity.Threecity;
import com.zhouyibike.uu.ui.adapter.Cityt2Adapter;
import com.zhouyibike.uu.ui.adapter.CitytAdapter;
import com.zhouyibike.uu.ui.base.BaseActivity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class CitytActivity extends BaseActivity {
    private ListView citylv;
    private CitytAdapter adapter1;
    private List<Cityinfo> curCity;
    private TextView mBtnTitle;
    private Mycity2 Curcity;
    private ArrayList<Mycity2.CitiesBean>  listcity=new ArrayList<>();
    private Threecity mycity;
    private Cityt2Adapter cityt2Adapter;
    private ArrayList<String> zuihoulist=new ArrayList<>();
    private String shiname;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cityt);
        /******/
//        citylv= (ListView) findViewById(R.id.citylv);
////        curCity= (List<Cityinfo>) getIntent().getSerializableExtra("citylist");
//        Curcity= (Mycity2) getIntent().getSerializableExtra("citylist");
//        listcity= (ArrayList<Mycity2.CitiesBean>) Curcity.getCities();
//        adapter1=new CitytAdapter(this,listcity);
//        citylv.setAdapter(adapter1);
//        mBtnTitle= (TextView) findViewById(R.id.bar_text_title);
//        mBtnTitle.setText("选择市区");
//        citylv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Intent i=new Intent();
//                i.putExtra("cityname",listcity.get(position).getCityName());
//                setResult(1,i);
//                finish();
//            }
//        });
        /******/
        citylv= (ListView) findViewById(R.id.citylv);
//        curCity= (List<Cityinfo>) getIntent().getSerializableExtra("citylist");
        mycity= (Threecity) getIntent().getSerializableExtra("citylist");
        cityt2Adapter=new Cityt2Adapter(this, (ArrayList<Threecity.CitiesBean>) mycity.getCities());
        citylv.setAdapter(cityt2Adapter);
        mBtnTitle= (TextView) findViewById(R.id.bar_text_title);
        mBtnTitle.setText("区域");
        citylv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                shiname=mycity.getCities().get(position).getCity();
                zuihoulist.clear();
                zuihoulist= (ArrayList<String>) mycity.getCities().get(position).getAreas();
                if (zuihoulist!=null&&zuihoulist.size()>0)
                {
                    Intent i=new Intent(CitytActivity.this,Cityt3Activity.class);
                    i.putExtra("citylist", (Serializable) zuihoulist);
                    startActivityForResult(i,200);
                }else{
                    Intent i=new Intent();
                    i.putExtra("cityname",shiname);
                    setResult(1,i);
                    finish();
                }
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==200&&resultCode==1)
        {
            Intent i=new Intent();
            i.putExtra("cityname",shiname+data.getStringExtra("cityname"));
            setResult(1,i);
            finish();
        }
    }
}
